package com.dalston.util.json;

import com.dalston.util.CommonResult;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.lang.reflect.Field;

/**
 * @author jh.pei
 * @date 2021/4/2 15:46
 */
public class PhoneNuberSerializer extends StdSerializer<CommonResult> {

    @Override
    public void serialize(CommonResult commonResult, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeNumber(commonResult.getCode());
        jsonGenerator.writeObject(commonResult.getData());
        jsonGenerator.writeString(commonResult.getMsg());
    }
    public Object objectDerictor(CommonResult commonResult) throws NoSuchFieldException, IllegalAccessException {
        Object object = commonResult.getData();
        Field f = object.getClass().getField("phoneNumber");
        f.setAccessible(true);
        f.set(object,"123");
        return object;
    }
    protected PhoneNuberSerializer() {
        super(CommonResult.class);
    }
}
